﻿var GetDataJSON = function () { };
var checkStatus = function (str) { return str == "SUCCESS" ? true : false; }
var _geturl = "http://1.shhomer.sinaapp.com/output/";
GetDataJSON.prototype.geturl = _geturl;
//获取用户所有网关
GetDataJSON.prototype.GetGates = function (_openid, callback) {
    var url = this.geturl + "GetGates.php";
    var para = { openid: _openid };
    $.get(url, para, function (result) {
        if (typeof (callback) != 'undefined') {
            callback(result);
        }
    }, "json");
}
//获取网关状态
GetDataJSON.prototype.GetGateStatus = function (_did, callback) {
    var url = this.geturl + "GetGateStatus.php";
    var para = { openid: _baseModel.openid, did: _did };
    $.get(url, para, function (data) {
        if (typeof (callback) != 'undefined') {
            callback(data);
        }
    }, "json");
}
//修改网关状态
GetDataJSON.prototype.ChangeGateInfo = function (model, callback) {
    var url = this.geturl + "ChangeGateInfo.php";
    var para = { openid: _baseModel.openid, did: model.did, relation: model.relation, name: model.name, prov: model.prov, cityname: model.cityname };
    $.get(url, para, function (data) {
        if (typeof (callback) != 'undefined') {
            callback(data);
        }
    }, "json");
}
//获取警告信息
GetDataJSON.prototype.GetWarningInfo = function (callback) {
    var url = this.geturl + "SelectReminders.php";
    var para = { openid: _baseModel.openid, did: _baseModel.did };
    $.get(url, para, function (data) {
        if (typeof (callback) != 'undefined') {
            callback(data);
        }
    }, "json");
}
//获取当天最后数据集合
GetDataJSON.prototype.SelectLast = function (callback) {
    var url = this.geturl + "SelectLast.php";
    var para = { openid: _baseModel.openid, did: _baseModel.did };
    $.get(url, para, function (data) {
        if (typeof (callback) != 'undefined') {
            callback(data);
        }
    }, "json");
}
//获取当天数据
GetDataJSON.prototype.SelectDataToday = {
    geturl: _geturl + "SelectDataToday.php",
    //获取当天吃药数据
    takepills: function (callback) {
        var para = { openid: _baseModel.openid, did: _baseModel.did, cid: "013" };
        $.get(this.geturl, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //获取当天血压与心率数据
    bloodpressure_heartrate: function (callback) {
        var para = { openid: _baseModel.openid, did: _baseModel.did, cid: "567" };
        $.get(this.geturl, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //获取当天开火数据
    openfire: function (callback) {
        var para = { openid: _baseModel.openid, did: _baseModel.did, cid: "005" };
        $.get(this.geturl, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //获取当天厨房活动数据
    kitchenactivity: function (callback) {
        var para = { openid: _baseModel.openid, did: _baseModel.did, cid: "006" };
        $.get(this.geturl, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //获取当天光度数据
    light: function (callback) {
        var para = { openid: _baseModel.openid, did: _baseModel.did, cid: "011" };
        $.get(this.geturl, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //获取当天开关门数据
    dooronoff: function (callback) {
        var para = { openid: _baseModel.openid, did: _baseModel.did, cid: "003" };
        $.get(this.geturl, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //获取当天室内活动数据
    indooractivity: function (callback) {
        var para = { openid: _baseModel.openid, did: _baseModel.did, cid: "010" };
        $.get(this.geturl, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    }
}
//获取指定时间内数据
GetDataJSON.prototype.SelectData = {
    geturl: _geturl + "SelectData.php",
    //获取吃药数据
    takepills: function (datearray, callback) {
        var para = {
            openid: _baseModel.openid, did: _baseModel.did, starttime: datearray.starttime, endtime: datearray.endtime, cid: "013"
        };
        $.get(this.geturl, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //获取血压与心率数据
    bloodpressure_heartrate: function (datearray, callback) {
        var para = {
            openid: _baseModel.openid, did: _baseModel.did, starttime: datearray.starttime, endtime: datearray.endtime, cid: "567"
        };
        $.get(this.geturl, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //获取开火数据
    openfire: function (datearray, callback) {
        var para = {
            openid: _baseModel.openid, did: _baseModel.did, starttime: datearray.starttime, endtime: datearray.endtime, cid: "005"
        };
        $.get(this.geturl, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //获取厨房活动数据
    kitchenactivity: function (datearray, callback) {
        var para = {
            openid: _baseModel.openid, did: _baseModel.did, starttime: datearray.starttime, endtime: datearray.endtime, cid: "006"
        };
        $.get(this.geturl, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //获取光度数据
    light: function (datearray, callback) {
        var para = {
            openid: _baseModel.openid, did: _baseModel.did, starttime: datearray.starttime, endtime: datearray.endtime, cid: "011"
        };
        $.get(this.geturl, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //获取开关门数据
    dooronoff: function (datearray, callback) {
        var para = {
            openid: _baseModel.openid, did: _baseModel.did, starttime: datearray.starttime, endtime: datearray.endtime, cid: "003"
        };
        $.get(this.geturl, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //获取室内活动数据
    indooractivity: function (datearray, callback) {
        var para = {
            openid: _baseModel.openid, did: _baseModel.did, starttime: datearray.starttime, endtime: datearray.endtime, cid: "010"
        };
        $.get(this.geturl, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    }
}
//绑定网关
GetDataJSON.prototype.BindGate = function (_did, callback) {
    var url = this.geturl + "BindGate.php";
    var para = {
        openid: _baseModel.openid, did: _did
    };
    $.get(url, para, function (data) {
        if (typeof (callback) != 'undefined') {
            callback(data);
        }
    }, "json");
}
//取消网关绑定
GetDataJSON.prototype.UnbindGate = function (_did, callback) {
    var url = this.geturl + "UnbindGate.php";
    var para = {
        openid: _baseModel.openid, did: _did
    };
    $.get(url, para, function (data) {
        if (typeof (callback) != 'undefined') {
            callback(data);
        }
    }, "json");
}
//操作生日
GetDataJSON.prototype.BirthdayMethods = {
    geturl: _geturl,
    //查询生日列表
    SelectBirthday: function (callback) {
        var url = this.geturl + "SelectBirthday.php";
        var para = {
            openid: _baseModel.openid, did: _baseModel.did
        };
        $.get(url, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //新增生日信息
    AddBirthday: function (model, callback) {
        var url = this.geturl + "AddBirthday.php";
        var para = {
            openid: _baseModel.openid, did: _baseModel.did, title: model.title, starttime: model.starttime, contt: model.contt, onoff: model.onoff, memono: model.id
        };
        $.get(url, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //修改生日信息
    ChangeBirthday: function (model, callback) {
        var url = this.geturl + "ChangeBirthday.php";
        var para = {
            openid: _baseModel.openid, did: _baseModel.did, title: model.title, starttime: model.starttime, contt: model.contt, onoff: model.onoff, memono: model.id
        };
        $.get(url, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //删除生日信息
    DelHoliBirthday: function (model, callback) {
        var url = this.geturl + "DelHoliBirthday.php";
        var para = {
            openid: _baseModel.openid, did: _baseModel.did, memono: model.id
        };
        $.get(url, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    }
}
//操作节日
GetDataJSON.prototype.HolidayMethods = {
    geturl: _geturl,
    //查询节日列表
    SelectHoliday: function (callback) {
        var url = this.geturl + "SelectHoliday.php";
        var para = {
            openid: _baseModel.openid, did: _baseModel.did
        };
        $.get(url, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //新增节日信息
    AddHoliday: function (model, callback) {
        var url = this.geturl + "AddHoliday.php";
        var para = {
            openid: _baseModel.openid, did: _baseModel.did, title: model.title, starttime: model.starttime, contt: model.contt, onoff: model.onoff, memono: model.id
        };
        $.get(url, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //修改节日信息
    ChangeHoliday: function (model, callback) {
        var url = this.geturl + "ChangeHoliday.php";
        var para = {
            openid: _baseModel.openid, did: _baseModel.did, title: model.title, starttime: model.starttime, contt: model.contt, onoff: model.onoff, memono: model.id
        };
        $.get(url, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    },
    //删除节日信息
    DelHoliBirthday: function (model, callback) {
        var url = this.geturl + "DelHoliBirthday.php";
        var para = {
            openid: _baseModel.openid, did: _baseModel.did, memono: model.id
        };
        $.get(url, para, function (data) {
            if (typeof (callback) != 'undefined') {
                callback(data);
            }
        }, "json");
    }
}
GetDataJSON.prototype.SelectProvince = function (callback) {
    var url = _geturl + "SelectProvince.php";
    var para = {
        openid: _baseModel.openid, did: _baseModel.did
    };
    $.get(url, para, function (data) {
        if (typeof (callback) != 'undefined') {
            callback(data);
        }
    }, "json");
}
GetDataJSON.prototype.SelectCounties = function (province, callback) {
    var url = _geturl + "SelectCounties.php";
    var para = { openid: _baseModel.openid, did: _baseModel.did, proven: model.areaID };
    $.get(url, para, function (data) {
        if (typeof (callback) != 'undefined') {
            callback(data);
        }
    }, "json");
}
GetDataJSON.prototype.AddSuggestion = function (content, callback) {
    var url = _geturl + "AddSuggestion.php";
    var para = { openid: _baseModel.openid, contt: content };
    $.get(url, para, function (data) {
        if (typeof (callback) != 'undefined') {
            callback(data);
        }
    }, "json");
}
GetDataJSON.prototype.GetImg = function (did, callback) {
    var url = _geturl + "GetImg.php";
    var result = url + "?openid=" + _baseModel.openid + "&did=" + did;
    if (typeof (callback) != 'undefined') {
        callback(data);
    }
    return result;
}
//GetDataJSON.prototype.ControlGate = {

//}
